﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace FuncWorks.Xna.UI.Menu
{
    public class SelectItem : IMenuItem
    {
        public string Title { get; set; }
        public bool Enabled { get; set; }
        public bool Hidden { get; set; }
        public float Height { get; set; }

        float width;
		BlockAlignment align;
        Vector2 current;

		public SelectItem(string title, BlockAlignment alignment)
        {
            Title = title;
            Enabled = true;
            Hidden = false;
            align = alignment;
            current = new Vector2();
        }

        public void Activate() { }
        public void MoveLeft() { }
        public void MoveRight() { }

        public float CalculateHeight(TextStyle textStyle, bool selected)
        {
            Vector2 size = textStyle.MeasureString(Title);
            Height = size.Y;
            width = size.X;
            return Height;
        }

        public void Draw(SpriteBatch spriteBatch, TextStyle textStyle, float currentY, Rectangle targetRectangle, bool selected)
        {
            current.Y = currentY;
            switch (align)
            {
				case BlockAlignment.Right: current.X = targetRectangle.Right - width; break;
				case BlockAlignment.Center: current.X = targetRectangle.Center.X - (int)Math.Ceiling(width / 2.0f); break;
                default: current.X = targetRectangle.Left; break;
            }
            textStyle.DrawString(spriteBatch, Title, current);
        }
    }
}
